#ifndef ZMQSOCKET
#define ZMQSOCKET

#include <mutex>
#include <zmq.hpp>
#include <zmq_addon.hpp>
#include <QJsonObject>
#include <QHash>

struct zmqSocket{
public:
    zmqSocket(const QJsonObject& aConfig, zmq::context_t& aContext);
    ~zmqSocket();
    QString address;
    bool recv = true;
    bool conn = false;
    bool isconnected = false;
    std::unique_ptr<zmq::socket_t> sock;
};

class zmqSockets{
public:
    zmqSockets(const QString& aName = "");
    ~zmqSockets();
    void add(const QJsonObject& aConfig);
    std::shared_ptr<zmqSocket> socket(const QString& aName) {return m_sockets.value(aName);}
private:
    zmq::context_t m_context{1};
    std::mutex m_sockets_lock;
    QHash<QString, std::shared_ptr<zmqSocket>> m_sockets;
    std::mutex m_sockets_ids_lock;
    QHash<void*, QString> m_sockets_ids;
    std::mutex m_recv_sockets_lock;
    std::vector<zmq::pollitem_t> m_recv_sockets;
};

#endif
